<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>信息管理</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" href="__ADMIN__css/style.css"  media="all">
  <link rel="stylesheet" href="__ADMIN__layui/css/layui.css"  media="all">
  <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>
<div class="pad-20">
<fieldset class="layui-elem-field layui-field-title">
<legend>信息管理</legend>
</fieldset>
<div class="news_search" style="margin-bottom:20px;">
  <div class="layui-block clearfix ">
    <!---->
    <div class="layui-block col-left">
      <div class="layui-form">
      <div class="layui-input-inline">
        <select id="batchid" name="batchid" lay-verify="required">
        <option value="">请选择操作</option>
        <option value="1">审核通过</option>
        <option value="2">取消审核</option>
        <option value="3">热门推荐</option>
        <option value="4">取消推荐</option>
        <option value="5">批量删除</option>
      </select>
      </div>
      <button class="layui-btn batch-btn">操作</button>
    </div>
    </div>
    <!---->
    <div class="layui-block col-right">
      <div class="layui-inline">
        <a class="layui-btn layui-btn-normal newsAdd_btn" href="{:U('add')}"><i class="layui-icon">&#xe61f;</i> 添加文章</a>
      </div>
      <div class="layui-inline">
        <form class="layui-form" action="{:U('index')}" method="get">
          <div class="layui-input-inline">
            <select name="catid">
            <option value="">请选择栏目</option>
            <volist name="categorys" id="vo">
              <option value="{$vo['id']}">{$vo['title']}</option>
            </volist>
          </select>
          </div>
          <div class="layui-input-inline">
            <input value="" placeholder="请输入文章标题" class="layui-input search_input" name="q" style="width:300px;" type="text" value="{$keywords}">
          </div>
          <button class="layui-btn" lay-submit="">查询</button>
        </form>
      </div>
    </div>
  </div>
</div>
<form name="myform" id="myform" action="" method="post">
<div class="layui-form">
  <table class="layui-table">
    <colgroup>
      <col width="50">
      <col width="60">
      <col>
      <col width="120">
      <col width="120">
      <!-- <col width="120"> -->
      <col width="170">
      <col width="260">
    </colgroup>
    <thead>
      <tr>
        <th><input type="checkbox" name="" lay-skin="primary" lay-filter="allChoose"></th>
        <th>排序</th>
        <th>标题</th>
        <th>栏目</th>
        <th>审核状态</th>
        <!-- <th>操作者</th> -->
        <th>更新时间</th>
        <th>管理操作</th>
      </tr>
    </thead>
    <tbody>
    <volist name="lists" id="val">
      <tr>
        <td><input type="checkbox" value="{$val['id']}" name="id[]" lay-skin="primary" lay-filter="itemChoose"></td>
        <td>{$val['sort']}</td>
        <td>{$val['title']}
          <if condition="$val['is_recom'] eq 1">&nbsp;&nbsp;<span class="red">[推荐]</span></if>
          <if condition="$val['thumb'] neq ''">&nbsp;&nbsp;<span class="blue">[文件]</span></if>
        </td>
        <td>{$category[$val['catid']]['title']}</td>
        <td>{$val['status']}</td>
        <!-- <td><php>$admininfo = get_adminInfo($val['adminid']);echo $admininfo['username']</php></td> -->
        <td>{:date('Y-m-d H:i:s',$val['create_time'])}</td>
        <td>
          <a class="layui-btn layui-btn-primary layui-btn-mini" href="javascript:;" dataurl="{:U('Home/Index/view',array('catid'=>$val['catid'],'id'=>$val['id']))}">预览</a>
          <a class="layui-btn layui-btn-mini layui-btn-warm" href="{:U('edit',array('id'=>$val['id']))}"><i class="layui-icon">&#xe642;</i>编辑</a>
          <a class="layui-btn layui-btn-danger layui-btn-mini news_del" data-id={$val['id']}><i class="layui-icon">&#xe640;</i>删除</a>
        </td>
      </tr>
    </volist>
    </tbody>
  </table>
</div>
</form>
<div class="laypage">{$page}</div>
</div>
<div class="yzui-filler"></div>
<script src="__ADMIN__js/jquery-1.9.1.min.js" charset="utf-8"></script>
<script src="__ADMIN__layui/layui.js" charset="utf-8"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script>
layui.use(['form'], function(){
  var form = layui.form,layer = layui.layer;
  //全选
  form.on('checkbox(allChoose)', function(data){
      var child = $(data.elem).parents('table').find('tbody input[type="checkbox"]');
      child.each(function(index, item){
          item.checked = data.elem.checked;
      });
      form.render('checkbox');
  });
});
$(".batch-btn").click(function(){
  if($("input[name='id[]']:checked").length <= 0){
    layer.alert('请选择您要操作的数据',{icon:5});
    return false;
  }
  if($("#batchid").val() == ""){
    $("#batchid").addClass("layui-form-danger");
    layer.alert('请选择您要进行的操作',{icon:5});
    return false;
  }
  var chk_value =[];
  $("input[name='id[]']:checked").each(function(){
    chk_value.push($(this).val());
  });
  if($("#batchid").val() == 5){
    layer.confirm('确定删除选中信息，无法恢复？',{icon:3, title:'提示信息'},function(index){
      $.post("{:U('batch')}",{ids:chk_value,action:$("#batchid").val()},function(result){
        if(result == 1){
          window.location.reload();
          //layer.alert('操作成功');
        }else if(result == 0){
          layer.alert('服务器正忙，请稍后再试');
        }else{
          layer.alert('您没有权限访问');
        }
      });
    });
  }else{
    $.post("{:U('batch')}",{ids:chk_value,action:$("#batchid").val()},function(result){
      if(result == 1){
        window.location.reload();
        //layer.alert('操作成功');
      }else if(result == 0){
        layer.alert('服务器正忙，请稍后再试');
      }else{
        layer.alert('您没有权限访问');
      }
    });
  }

});
$(".news_del").click(function(){
  var _this = $(this);
  layer.confirm('确定删除此信息？',{icon:3, title:'提示信息'},function(index){
    var dataid = _this.attr("data-id");
    $.post("{:U('del')}",{id:dataid},function(result){
      if(result == 1){
        _this.parents("tr").remove();
        layer.close(index);
      }else if(result == 0){
        layer.alert('服务器正忙，请稍后再试');
      }else{
        layer.alert('您没有权限访问');
      }
    });
  });
});
$(".layui-btn-primary").click(function(){
  var dataurl = $(this).attr('dataurl');
  layer.open({
  type: 2,
  title: '在线预览',
  shadeClose: true,
  shade: 0.8,
  area: ['100%', '100%'],
  content: dataurl //iframe的url
  });
})
</script>
</body>
</html>
